// 企业信息
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/jsonserialize/company/data.dart';
import 'package:im_flutter_sdk_example/jsonserialize/recommend/newsDetail.dart';
import 'package:im_flutter_sdk_example/pages/company/content.dart';
import 'package:im_flutter_sdk_example/pages/company/head.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';

class CompanyPage extends StatefulWidget {
  @override
  _CompanyInfoState createState() => _CompanyInfoState();
}

class _CompanyInfoState extends State<CompanyPage> {
  List<CompanyInfo> companys = [];
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      this._reqCompanyInfo();
    });
  }

  _reqCompanyInfo() async {
    G.showLoading(status: '加载中...');
    Map arguments = ModalRoute.of(context).settings.arguments;
    if (arguments != null) {
      NewsDetailsData item = arguments['item'] as NewsDetailsData;
      String keyword = item.kwdWord[0];
      if (keyword != null) {
        var res = await G.req.company.getInfo(keyword: keyword);
        // var res = await G.req.company.getInfo(keyword: item.kwdWord.join(","));
        var data = res.data;
        if (data['status'] == 1) {
          var resData = res.data['data'];
          resData.forEach((json) {
            CompanyInfo _companyInfo = CompanyInfo.fromJson(json);
            companys.add(_companyInfo);
          });
        }
        setState(() {});
      }
    }
    G.dismissLoading();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('企业信息')),
        body: Container(
            child: SingleChildScrollView(
          child:
              Column(children: companys.map((e) => _buildContent(e)).toList()),
        )));
  }

  Widget _buildContent(CompanyInfo info) {
    return Container(
      margin: EdgeInsets.only(bottom: 10),
      child: Column(
        children: [
          CompanyHeader(
            item: info,
          ),
          BasicCompanyInfo(item: info)
        ],
      ),
    );
  }
}
